package com.jron.cqiu.util;

import org.apache.commons.lang.text.StrTokenizer;
import org.apache.commons.lang.text.StrMatcher;

/**
 * Created by Intellij IDEA.
 *
 * @Author: Yejw
 * @Date: 2008-6-23
 * @Time: 16:18:17
 */
public class StrUtil {

    /**
     * @param arg
     * @return
     */
    public static String[] argsToStringArray(String arg) {
        return argsToStringArray(arg, null);
    }

    /**
     * @param arg
     * @param delimiterMatcher
     * @return
     */
    public static String[] argsToStringArray(String arg, StrMatcher delimiterMatcher) {
        StrTokenizer tok = new StrTokenizer(arg);
        tok.setDelimiterMatcher((delimiterMatcher == null ? StrMatcher.spaceMatcher() : delimiterMatcher));
        tok.setQuoteMatcher(StrMatcher.doubleQuoteMatcher());
        tok.setIgnoredMatcher(StrMatcher.noneMatcher());
        tok.setIgnoreEmptyTokens(true);
        return tok.getTokenArray();
    }

}
